<?php

    header("Content-Type: text/plain");
    
    //get information
    $sName = $_POST["userName"];
    
    //status message
    $sStatus = "";
        
    //database information
    $sDBServer = "localhost:8889";
    $sDBName = "cultura";
    $sDBUsername = "root";
    $sDBPassword = "root";


    //create the SQL query string
    $sQuery = "SELECT * FROM usuarios where login='".$sName."'";

    $oLink = mysql_connect($sDBServer,$sDBUsername,$sDBPassword);
    @mysql_select_db($sDBName) or $sStatus = "Unable to open database";
        
    if ($sStatus == '') {
		if($oResult = mysql_query($sQuery) and mysql_num_rows($oResult) > 0) {
            $aValues = mysql_fetch_array($oResult,MYSQL_ASSOC);
            $pass= md5($_POST['password']);
			if($pass == $aValues['pass'] ){
				$sStatus = "Bienvenido al Sistema :D !";
			}else{
				$sStatus = "Contraseña no válida";
			}
         } else {
            $sStatus = "No existe el usuario";
        }
    }
    
    mysql_free_result($oResult);
    mysql_close($oLink);
    
    echo $sStatus;
?>